<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of MemberService
 *
 * @author Desmond
 */
class MemberService {

    //put your code here
    public function checkMemberExistByFbID($fb_id) {
        $get = mysql_query("select count(*) as result from tbl_member where fb_id='$fb_id'");

        if (mysql_result($get, 0, "result") > 0) {
            return true;
        } else {
            return false;
        }
    }

    public function getMember($where) {


        $get = mysql_query("select * from tbl_member $where") or die(mysql_error());

        $count = 0;
        $data;

        if (mysql_num_rows($get) > 0) {
            while ($a = mysql_fetch_assoc($get)) {
                $mem = new TblMember();
                $mem->setId($a['id']);
                $mem->setAge($a['age']);
                $mem->setCreated_datetime($a['created_datetime']);
                $mem->setDob($a['dob']);
                $mem->setEmail($a['email']);
                $mem->setFb_id($a['fb_id']);
                $mem->setMember_name($a['member_name']);
                $mem->setIc_number($a['ic_number']);
                $mem->setId($a['id']);
                $mem->setMobile_number($a['mobile_number']);
                $mem->setMobile_prefix($a['mobile_prefix']);
                $mem->setSchool($a['school']);
                $mem->setCollege($a['college']);
                $mem->setDepartment($a['department']);
                $mem->setBusiness_division($a['business_division']);
                $mem->setCountry_based($a['country_based']);
                $mem->setRegistered_name($a['registered_name']);
                $mem->setRegistration_status($a['registration_status']);
                $mem->setState_id($a['state_id']);

                $data[$count] = $mem;
                $count++;
                
            }
            
            return $data;
        } else {
            return false;
        }
    }

    public function insertMember(TblMember $tbl_member) {

        mysql_query("INSERT INTO tbl_member (`member_name`, `fb_id`, `email`, `registered_name`, 
            `ic_number`, `dob`,`state_id`, `created_datetime`, `registration_status`,`status`) 
            VALUES ('" . $tbl_member->getMember_name() . "', '" . $tbl_member->getFb_id() . "','" . $tbl_member->getEmail() . "', 
                '" . $tbl_member->getRegistered_name() . "', '" . $tbl_member->getIc_number() . "', '" . $tbl_member->getDob() . "', '" . $tbl_member->getState_id() . "', '" . $tbl_member->getCreated_datetime() . "', 
                    '" . $tbl_member->getRegistration_status() . "','" . $tbl_member->getStatus() . "')") or die(mysql_error());

        $id = mysql_insert_id();

        return $id;
    }

    public function updateMember(TblMember $tbl_member) {

        mysql_query("update tbl_member set email='" . $tbl_member->getEmail() . "',member_name='" . mysql_real_escape_string($tbl_member->getMember_name()) . "',ic_number='" . $tbl_member->getIc_number() . "',
            dob='" . $tbl_member->getDob() . "',mobile_prefix='" . $tbl_member->getMobile_prefix() . "',mobile_number='" . $tbl_member->getMobile_number() . "',school='" . $tbl_member->getSchool() . "',college='".$tbl_member->getCollege()."',
            department='" . $tbl_member->getDepartment() . "',business_division='" . $tbl_member->getBusiness_division() . "',country_based='" . $tbl_member->getCountry_based() . "', 
                registration_status='" . $tbl_member->getRegistration_status() . "' where id='".$tbl_member->getId()."'") or die(mysql_error());
    }

}

?>
